<?php
define('IS_UNIT_TESTING',true);
require_once(dirname(__FILE__)."/../src/core/Bootstrap.php");
/**
 * Unit Test Bootstrap Class
 *
 * @author mpike
 */
class TestingBootstrap extends Bootstrap{

	public static $_instance = null;

	public static function getInstance(){
		if(self::$_instance===null){
			self::$_instance = new self();
		}
		return self::$_instance;
	}

	/**
	 * Dont instantiate directly, use getInstance()
	 */
	public function __construct(){
		require_once(dirname(__FILE__)."/../src/SiteConfig.php");
		require_once(dirname(__FILE__)."/../src/GameConfig.php");
		require_once(dirname(__FILE__)."/../src/core/UnitTest.php");
		$this->loadCoreResources();
	}

	/**
	 * Dispatch Request To Releveant Controller+Action
	 *
	 * @return array
	 */
	public function dispatchRequest(array $request){
		$controller = Request::getWord("c",null,$request);
		$action 	= Request::getWord("a",null,$request);

		if(!$controller || !$action){
			throw new BadRequest("Invalid controller/action: c=$controller a=$action");
		}

		if($this->loadController($controller) && $this->actionExists($controller,$action)){
			return $this->callAction($controller, $action, $request);
		}else{
			throw new BadRequest("Unrecognised controller: ".$controller);
		}
	}
}
TestingBootstrap::getInstance();